﻿using SYJ.BLL;
using SYJ.Common.web;
using SYJ.IBLL;
using SYJ.Model;
using SYJ.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace SYJ.Logic.Controllers.admin
{
   public class PermissionMgrController:BaseController
    {
       private ISysPermissionBLL bll = new SysPermissionBLL();
        public ActionResult Index()
        {

            return View();
        }
        public ActionResult GetPermissionList(QueryModel query, string name)
        {
            long count = 0;
            if (!string.IsNullOrEmpty(name))
            {
                query.SqlWhere = " and name like ?name ";
                query.Param.Add( "name",  "%" + name + "%" );
            }
            List<SysPermission> list = bll.GetPage(query, out count);
            var respose = JsonLayuiGridData<SysPermission>.Create(query, list, count, "");
            return Json(respose, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public ActionResult AddOrUp(int? id)
        {
            SysPermission role = new SysPermission();
            if (id != null)
            {
                role = bll.GetModel(Convert.ToInt32(id));
            }
            return View(role);
        }
        [HttpPost]
        public ActionResult AddOrUp(SysPermission model)
        {
            if (model.id > 0)
            {
                return Json(bll.Update(model), JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(bll.Insert(model), JsonRequestBehavior.AllowGet);
            }
        }

        public ActionResult Delete(int id)
        {
            bool delete = bll.Delete(new SysPermission() { id = id });
            return Json(delete, JsonRequestBehavior.AllowGet);
        }
    }
}
